package com.ymatou.paygetway.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.payment.parameter.AcquireOrderBean;
import com.ymatou.iapi.payment.service.ExecuteRefundCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.paygetway.parameter.UserNotifyBean;
import com.ymatou.paygetway.service.UserNotifyCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.database.model.FqlMember;
import com.ymttest.database.model.FqlMemberExample;
import com.ymttest.database.model.MPayment;
import com.ymttest.database.sqlwapper.PayGateWayWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
/**
*分期乐用户通知
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UserNotify{
	private static UserNotifyBean usernotifyBean;
	private static UserNotifyCall usernotifyCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("分期乐用户通知");
	}

	@Before
	public void caseUp() {
		usernotifyBean=new UserNotifyBean();
		usernotifyCall=new UserNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(usernotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void addMock(UserNotifyCall cpcall, Map m) {
		Logger.comment("初始化MockHeader信息:" + m.toString());
		Set sl = m.entrySet();
		for (Object o : sl) {
			String[] ss = o.toString().split("=");
			String value = FormatUtil.urlEncode(ss[1]);
			cpcall.addHeader(ss[0], value);
		}
	}
	private Map CodeMockMap() throws Exception {
		Logger.comment("获取默认的Mock信息");
		Map m = new HashMap<String, String>();
		m.put("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		m.put("MockId", mockid);
		String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
		m.put("MockResult-FqlPay-open_id", openid);
//		usernotifyCall.addHeader("MockResult-FqlPay-open_id", openid);
		String rtoken=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
		m.put("MockResult-FqlPay-refresh_token", rtoken);
//		usernotifyCall.addHeader("MockResult-FqlPay-refresh_token", rtoken);
		String atoken=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
		m.put("MockResult-FqlPay-access_token", atoken);
//		usernotifyCall.addHeader("MockResult-FqlPay-access_token", atoken);
		return m;
	}
	private Map CreditMockMap() throws Exception {
		Logger.comment("获取默认的Mock信息");
		Map m = new HashMap<String, String>();
		m.put("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		m.put("MockId", mockid);
//		MockResult-FqlPay-total_credit: 500
		m.put("MockResult-FqlPay-total_credit", 600);
//		MockResult-FqlPay-total_avl_credit: 200
		m.put("MockResult-FqlPay-total_avl_credit", 210);
//		MockResult-FqlPay-new_user_flag: 1
		m.put("MockResult-FqlPay-new_user_flag", 2);
//		MockResult-FqlPay-credit_grant_time: 2019-06-14 17:50:38
		m.put("MockResult-FqlPay-credit_grant_time", YMTDateUtil.getBeforeOrNextDay(0));
//		MockResult-FqlPay-max_overdue: 1
		m.put("MockResult-FqlPay-max_overdue", 12);
//		MockResult-FqlPay-user_repay_day: 2
		m.put("MockResult-FqlPay-user_repay_day", 2);
//		MockResult-FqlPay-month: 3
		m.put("MockResult-FqlPay-month", Calendar.getInstance().get(Calendar.MONTH));
//		MockResult-FqlPay-year: 2019
		m.put("MockResult-FqlPay-year", Calendar.getInstance().get(Calendar.YEAR));
//		MockResult-FqlPay-total_un_repay_amount: 2000
		m.put("MockResult-FqlPay-total_un_repay_amount",2000);
		return m;
	}
	/**
	 * 获取code成功 用于授信前置条件 授信的参数设置要在这之后做--公用bean call
	 * @param uid
	 * @throws Exception
	 */
	private Map CodeFin(Integer uid) throws Exception {
		PayGateWayCallService.RegFqlMember(uid); 
		usernotifyBean=PayGateWayCallService.initFQLCodeCallback(uid);
		usernotifyCall.setData(usernotifyBean);
		Map mcode=CodeMockMap();
		addMock(usernotifyCall, mcode);
		usernotifyCall.callService();
		usernotifyBean=new UserNotifyBean();
		usernotifyCall=new UserNotifyCall();
		return mcode;
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UserNotify_001() {
		Logger.start(true,"分期乐用户code推送通知成功-fenqile.auth.callback-落token");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			usernotifyBean=PayGateWayCallService.initFQLCodeCallback(uid);
			usernotifyCall.setData(usernotifyBean);
//			MockResult-FqlPay-open_id: xxx
//			MockResult-FqlPay-refresh_token: rrr
//			MockResult-FqlPay-access_token: aaa
//			String openid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
//			usernotifyCall.addHeader("MockResult-FqlPay-open_id", openid);
//			String rtoken=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
//			usernotifyCall.addHeader("MockResult-FqlPay-refresh_token", rtoken);
//			String atoken=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
//			usernotifyCall.addHeader("MockResult-FqlPay-access_token", atoken);
//			usernotifyCall.addHeader("Mock", "1");
//			String mockid = TestDataManager.getRandomUUID().toString();
//			usernotifyCall.addHeader("MockId", mockid);
			Map mcode=CodeMockMap();
			addMock(usernotifyCall, mcode);
			usernotifyCall.callService();
			Logger.verifyEquals("0", usernotifyCall.getString("result"), "验证result");
			FqlMemberExample example=new FqlMemberExample();
			example.createCriteria().andUserIdEqualTo(uid);
			List<FqlMember> dbs = new PayGateWayWapper().selectFqlMemberExample(example);
			Logger.verifyEquals(1, dbs.size(), "验证数据进入数据库");
			Logger.debug(FormatUtil.beanToGSONString(dbs));
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-open_id"), dbs.get(0).getFqlOpenId(), "验证FqlOpenId");
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-refresh_token"), dbs.get(0).getRefreshToken(), "验证RefreshToken");
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-access_token"), dbs.get(0).getAccessToken(), "验证AccessToken");
			Logger.verifyEquals(0, dbs.get(0).getState(), "验证State");
			Logger.verifyEquals(0, dbs.get(0).getNewUserFlag(), "验证NewUserFlag");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UserNotify_002() {
		Logger.start(true,"分期乐用户授信结果通知成功-fenqile.credit.callback-新用户");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			//获取openid
			String open_id=CodeFin(uid).get("MockResult-FqlPay-open_id").toString();
			Thread.sleep(2000);
			usernotifyBean=PayGateWayCallService.initFQLCreditCallback(uid);
			usernotifyBean.setOpen_id(open_id);
			usernotifyCall.setData(usernotifyBean);
			Map mcredit=CreditMockMap();
			addMock(usernotifyCall, mcredit);
			usernotifyCall.callService();			
			Logger.verifyEquals("0", usernotifyCall.getString("result"), "验证result");
			FqlMemberExample example=new FqlMemberExample();
			example.createCriteria().andUserIdEqualTo(uid);
			List<FqlMember> dbs = new PayGateWayWapper().selectFqlMemberExample(example);
			Logger.verifyEquals(1, dbs.size(), "验证数据进入数据库");
			Logger.debug(FormatUtil.beanToGSONString(dbs));
//			maxOverDue MockResult-FqlPay-max_overdue
//			newUserFlag MockResult-FqlPay-new_user_flag
//			creditGrantTime MockResult-FqlPay-credit_grant_time
//			totalCredit MockResult-FqlPay-total_credit
//			availableCredit MockResult-FqlPay-total_avl_credit
//			unReplayAmount MockResult-FqlPay-total_un_repay_amount
			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-max_overdue"), dbs.get(0).getMaxOverDue(), "验证MaxOverDue");
			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-new_user_flag"), dbs.get(0).getNewUserFlag(), "验证NewUserFlag");
//			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-credit_grant_time"), dbs.get(0).getCreditGrantTime(), "验证creditGrantTime");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_credit").toString()).setScale(2), dbs.get(0).getTotalCredit().setScale(2), "验证totalCredit");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_avl_credit").toString()).setScale(2), dbs.get(0).getAvailableCredit().setScale(2), "验证availableCredit");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_un_repay_amount").toString()).setScale(2), dbs.get(0).getUnReplayAmount().setScale(2), "验证unReplayAmount");
			Logger.verifyEquals(1, dbs.get(0).getState(), "验证State");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UserNotify_003() {
		Logger.start(true,"分期乐用户授信结果通知-不通过授信失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			//获取openid
			String open_id=CodeFin(uid).get("MockResult-FqlPay-open_id").toString();
			Thread.sleep(2000);
			usernotifyBean=PayGateWayCallService.initFQLCreditCallback(uid);
			usernotifyBean.setOpen_id(open_id);
			usernotifyBean.setType(1005);
			usernotifyCall.setData(usernotifyBean);
			Map mcredit=CreditMockMap();
			addMock(usernotifyCall, mcredit);
			usernotifyCall.callService();			
			Logger.verifyEquals("0", usernotifyCall.getString("result"), "验证result");
			FqlMemberExample example=new FqlMemberExample();
			example.createCriteria().andUserIdEqualTo(uid);
			List<FqlMember> dbs = new PayGateWayWapper().selectFqlMemberExample(example);
			Logger.verifyEquals(1, dbs.size(), "验证数据进入数据库");
			Logger.debug(FormatUtil.beanToGSONString(dbs));
			Logger.verifyEquals(2, dbs.get(0).getState(), "验证State");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UserNotify_004() {
		Logger.start(true,"分期乐用户授信结果通知成功-fenqile.credit.callback-老用户");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			//获取openid
			String open_id=CodeFin(uid).get("MockResult-FqlPay-open_id").toString();
			Thread.sleep(2000);
			usernotifyBean=PayGateWayCallService.initFQLCreditCallback(uid);
			usernotifyBean.setOpen_id(open_id);
			usernotifyCall.setData(usernotifyBean);
			Map mcredit=CreditMockMap();
			mcredit.put("MockResult-FqlPay-new_user_flag",3);
			addMock(usernotifyCall, mcredit);
			usernotifyCall.callService();			
			Logger.verifyEquals("0", usernotifyCall.getString("result"), "验证result");
			FqlMemberExample example=new FqlMemberExample();
			example.createCriteria().andUserIdEqualTo(uid);
			List<FqlMember> dbs = new PayGateWayWapper().selectFqlMemberExample(example);
			Logger.verifyEquals(1, dbs.size(), "验证数据进入数据库");
			Logger.debug(FormatUtil.beanToGSONString(dbs));
//			maxOverDue MockResult-FqlPay-max_overdue
//			newUserFlag MockResult-FqlPay-new_user_flag
//			creditGrantTime MockResult-FqlPay-credit_grant_time
//			totalCredit MockResult-FqlPay-total_credit
//			availableCredit MockResult-FqlPay-total_avl_credit
//			unReplayAmount MockResult-FqlPay-total_un_repay_amount
			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-max_overdue"), dbs.get(0).getMaxOverDue(), "验证MaxOverDue");
			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-new_user_flag"), dbs.get(0).getNewUserFlag(), "验证NewUserFlag");
//			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-credit_grant_time"), dbs.get(0).getCreditGrantTime(), "验证creditGrantTime");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_credit").toString()).setScale(2), dbs.get(0).getTotalCredit().setScale(2), "验证totalCredit");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_avl_credit").toString()).setScale(2), dbs.get(0).getAvailableCredit().setScale(2), "验证availableCredit");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_un_repay_amount").toString()).setScale(2), dbs.get(0).getUnReplayAmount().setScale(2), "验证unReplayAmount");
			Logger.verifyEquals(1, dbs.get(0).getState(), "验证State");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UserNotify_005() {
		Logger.start(true,"不存在用户分期乐用户code推送通知失败");
		try {
			int uid  = -1000;
			usernotifyBean=PayGateWayCallService.initFQLCodeCallback(uid);
			usernotifyCall.setData(usernotifyBean);
			usernotifyCall.callService();			
			Logger.verifyEquals("-1", usernotifyCall.getString("result"), "验证result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	public void Tc_UserNotify_006() {
		Logger.start(true,"分期乐用户授信结果通知成功-fenqile.credit.callback-未授信新用户");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			//获取openid
			String open_id=CodeFin(uid).get("MockResult-FqlPay-open_id").toString();
			Thread.sleep(2000);
			usernotifyBean=PayGateWayCallService.initFQLCreditCallback(uid);
			usernotifyBean.setOpen_id(open_id);
			usernotifyCall.setData(usernotifyBean);
			Map mcredit=CreditMockMap();
			mcredit.put("MockResult-FqlPay-new_user_flag",1);
			addMock(usernotifyCall, mcredit);
			usernotifyCall.callService();			
			Logger.verifyEquals("0", usernotifyCall.getString("result"), "验证result");
			FqlMemberExample example=new FqlMemberExample();
			example.createCriteria().andUserIdEqualTo(uid);
			List<FqlMember> dbs = new PayGateWayWapper().selectFqlMemberExample(example);
			Logger.verifyEquals(1, dbs.size(), "验证数据进入数据库");
			Logger.debug(FormatUtil.beanToGSONString(dbs));
//			maxOverDue MockResult-FqlPay-max_overdue
//			newUserFlag MockResult-FqlPay-new_user_flag
//			creditGrantTime MockResult-FqlPay-credit_grant_time
//			totalCredit MockResult-FqlPay-total_credit
//			availableCredit MockResult-FqlPay-total_avl_credit
//			unReplayAmount MockResult-FqlPay-total_un_repay_amount
			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-max_overdue"), dbs.get(0).getMaxOverDue(), "验证MaxOverDue");
			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-new_user_flag"), dbs.get(0).getNewUserFlag(), "验证NewUserFlag");
//			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-credit_grant_time"), dbs.get(0).getCreditGrantTime(), "验证creditGrantTime");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_credit").toString()).setScale(2), dbs.get(0).getTotalCredit().setScale(2), "验证totalCredit");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_avl_credit").toString()).setScale(2), dbs.get(0).getAvailableCredit().setScale(2), "验证availableCredit");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_un_repay_amount").toString()).setScale(2), dbs.get(0).getUnReplayAmount().setScale(2), "验证unReplayAmount");
			Logger.verifyEquals(1, dbs.get(0).getState(), "验证State");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UserNotify_007() {
		Logger.start(true,"分期乐用户授信结果通知成功-fenqile.credit.callback-未找到openid失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			//获取openid
			String open_id=CodeFin(uid).get("MockResult-FqlPay-open_id").toString();
			usernotifyBean=PayGateWayCallService.initFQLCreditCallback(uid);
//			usernotifyBean.setOpen_id(open_id);
			usernotifyCall.setData(usernotifyBean);
			Map mcredit=CreditMockMap();
			addMock(usernotifyCall, mcredit);
			usernotifyCall.callService();			
			Logger.verifyEquals("-1", usernotifyCall.getString("result"), "验证result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UserNotify_008() {
		Logger.start(true,"分期乐method回调method错误,失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			PayGateWayCallService.RegFqlMember(uid); 
			usernotifyBean=PayGateWayCallService.initFQLCodeCallback(uid);
			usernotifyBean.setMethod("fenqile.code.callback");
			usernotifyCall.setData(usernotifyBean);
			Map mcode=CodeMockMap();
			addMock(usernotifyCall, mcode);
			usernotifyCall.callService();
			Logger.verifyEquals("-1", usernotifyCall.getString("result"), "验证result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UserNotify_009() {
		Logger.start(true,"分期乐用户code推送通知成功-同一个fqlopenid被2个码头账户绑定,第二次绑定时也刷第一次的账号");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			
			UserRegisterInfoRequestDtoBean regbean2 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc2 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean2);
			JsonObject registerResult2 = urrc2.getJsonObject().get("Result").getAsJsonObject();
			String token2=registerResult2.get("Token").getAsString();
			int uid2  = urrc2.getUserid();
			
			
			PayGateWayCallService.RegFqlMember(uid); 
			usernotifyBean=PayGateWayCallService.initFQLCodeCallback(uid);
			usernotifyCall.setData(usernotifyBean);
			Map mcode=CodeMockMap();
			addMock(usernotifyCall, mcode);
			usernotifyCall.callService();
			Logger.verifyEquals("0", usernotifyCall.getString("result"), "验证result");
			FqlMemberExample example=new FqlMemberExample();
			example.createCriteria().andUserIdEqualTo(uid);
			List<FqlMember> dbs = new PayGateWayWapper().selectFqlMemberExample(example);
			Logger.verifyEquals(1, dbs.size(), "验证数据进入数据库");
			Logger.debug(FormatUtil.beanToGSONString(dbs));
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-open_id"), dbs.get(0).getFqlOpenId(), "验证FqlOpenId");
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-refresh_token"), dbs.get(0).getRefreshToken(), "验证RefreshToken");
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-access_token"), dbs.get(0).getAccessToken(), "验证AccessToken");
			Logger.verifyEquals(0, dbs.get(0).getState(), "验证State");
			Logger.verifyEquals(0, dbs.get(0).getNewUserFlag(), "验证NewUserFlag");
			
			usernotifyBean=PayGateWayCallService.initFQLCodeCallback(uid2);
			usernotifyCall=new UserNotifyCall();
			usernotifyCall.setData(usernotifyBean);
			String rtoken=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			mcode.put("MockResult-FqlPay-refresh_token", rtoken);
//			usernotifyCall.addHeader("MockResult-FqlPay-refresh_token", rtoken);
			String atoken=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			mcode.put("MockResult-FqlPay-access_token", atoken);
			addMock(usernotifyCall, mcode);
			usernotifyCall.callService();
			Logger.verifyEquals("0", usernotifyCall.getString("result"), "验证result");
			
			example=new FqlMemberExample();
			example.createCriteria().andUserIdEqualTo(uid2);
			dbs = new PayGateWayWapper().selectFqlMemberExample(example);
			Logger.verifyEquals(1, dbs.size(), "验证数据进入数据库");
			Logger.debug(FormatUtil.beanToGSONString(dbs));
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-open_id"), dbs.get(0).getFqlOpenId(), "验证FqlOpenId");
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-refresh_token"), dbs.get(0).getRefreshToken(), "验证RefreshToken");
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-access_token"), dbs.get(0).getAccessToken(), "验证AccessToken");
			Logger.verifyEquals(0, dbs.get(0).getState(), "验证State");
			Logger.verifyEquals(0, dbs.get(0).getNewUserFlag(), "验证NewUserFlag");
			
			example=new FqlMemberExample();
			example.createCriteria().andUserIdEqualTo(uid);
			dbs = new PayGateWayWapper().selectFqlMemberExample(example);
			Logger.verifyEquals(1, dbs.size(), "验证数据进入数据库");
			Logger.debug(FormatUtil.beanToGSONString(dbs));
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-open_id"), dbs.get(0).getFqlOpenId(), "验证FqlOpenId");
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-refresh_token"), dbs.get(0).getRefreshToken(), "验证RefreshToken");
			Logger.verifyEquals(mcode.get("MockResult-FqlPay-access_token"), dbs.get(0).getAccessToken(), "验证AccessToken");
			Logger.verifyEquals(0, dbs.get(0).getState(), "验证State");
			Logger.verifyEquals(0, dbs.get(0).getNewUserFlag(), "验证NewUserFlag");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UserNotify_010() {
		Logger.start(true,"分期乐用户授信结果通知成功-fenqile.credit.callback-新用户-返回报文异常数据");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid  = urrc.getUserid();
			//获取openid
			String open_id=CodeFin(uid).get("MockResult-FqlPay-open_id").toString();
			Thread.sleep(2000);
			usernotifyBean=PayGateWayCallService.initFQLCreditCallback(uid);
			usernotifyBean.setOpen_id(open_id);
			usernotifyCall.setData(usernotifyBean);
			Map mcredit=CreditMockMap();

//			MockResult-FqlPay-month: 3
			mcredit.put("MockResult-FqlPay-month", 0);
//			MockResult-FqlPay-year: 2019
			mcredit.put("MockResult-year", 0);
			mcredit.put("MockResult-FqlPay-user_repay_day", 0);
			addMock(usernotifyCall, mcredit);
			usernotifyCall.callService();			
			Logger.verifyEquals("0", usernotifyCall.getString("result"), "验证result");
			FqlMemberExample example=new FqlMemberExample();
			example.createCriteria().andUserIdEqualTo(uid);
			List<FqlMember> dbs = new PayGateWayWapper().selectFqlMemberExample(example);
			Logger.verifyEquals(1, dbs.size(), "验证数据进入数据库");
			Logger.debug(FormatUtil.beanToGSONString(dbs));
//			maxOverDue MockResult-FqlPay-max_overdue
//			newUserFlag MockResult-FqlPay-new_user_flag
//			creditGrantTime MockResult-FqlPay-credit_grant_time
//			totalCredit MockResult-FqlPay-total_credit
//			availableCredit MockResult-FqlPay-total_avl_credit
//			unReplayAmount MockResult-FqlPay-total_un_repay_amount
			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-max_overdue"), dbs.get(0).getMaxOverDue(), "验证MaxOverDue");
			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-new_user_flag"), dbs.get(0).getNewUserFlag(), "验证NewUserFlag");
//			Logger.verifyEquals(mcredit.get("MockResult-FqlPay-credit_grant_time"), dbs.get(0).getCreditGrantTime(), "验证creditGrantTime");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_credit").toString()).setScale(2), dbs.get(0).getTotalCredit().setScale(2), "验证totalCredit");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_avl_credit").toString()).setScale(2), dbs.get(0).getAvailableCredit().setScale(2), "验证availableCredit");
			Logger.verifyEquals(new BigDecimal(mcredit.get("MockResult-FqlPay-total_un_repay_amount").toString()).setScale(2), dbs.get(0).getUnReplayAmount().setScale(2), "验证unReplayAmount");
			Logger.verifyEquals(1, dbs.get(0).getState(), "验证State");
			String replay=YMTDateUtil.getFormatDateString( dbs.get(0).getReplayDate(), YMTDateUtil.YMDTHMS_STRING);
			Logger.verifyEquals("1971-01-01T00:00:00", replay, "验证ReplayDate");

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}